package com.budwk.app.sqfwV2.enums;

import com.budwk.app.sqfwDoc.codeGenerator.excelGenerate.BaseTemplateExcelGenerator;
import com.budwk.app.sqfwV2.generator.yuHong.BackPayGenerator;
import lombok.Getter;

import java.util.Arrays;
import java.util.Optional;

@Getter
public enum YuHongEnum {
    BACK_PAY("back_pay", new BackPayGenerator(), "", "sqfwV2/yuHong/backPay.xlsx", "九小场所", true, "【欠薪风险排查记录表】", "全部数据|九小场所", "/preview/safety/yh/欠薪_excel.png"),
    ;

    private final String code;

    private final BaseTemplateExcelGenerator service;

    private final String name;

    private final String templatePath;

    private final String type;

    private final boolean loop;

    private final String fileName;

    private final String label;

    private final String previewImage;


    YuHongEnum(String code, BaseTemplateExcelGenerator service, String name, String templatePath, String type, boolean loop, String fileName, String label, String previewImage) {
        this.code = code;
        this.service = service;
        this.name = name;
        this.templatePath = templatePath;
        this.type = type;
        this.loop = loop;
        this.fileName = fileName;
        this.label = label;
        this.previewImage = previewImage;
    }

    /**
     * @param code
     * @return
     */
    public static BaseTemplateExcelGenerator getService(String code) {
        Optional<YuHongEnum> optional = Arrays.stream(YuHongEnum.values()).filter(c -> code.equals(c.getCode())).findFirst();
        return optional.map(YuHongEnum::getService).orElse(null);
    }

    /**
     * @param code
     * @return
     */
    public static String getType(String code) {
        for (YuHongEnum o : YuHongEnum.values()) {
            if (o.getCode().equals(code)) {
                return o.getType();
            }
        }
        return null;
    }

    /**
     * @param code
     * @return
     */
    public static String getLabel(String code) {
        Optional<YuHongEnum> optional = Arrays.stream(values()).filter(e -> e.getCode().equals(code)).findFirst();
        return optional.map(YuHongEnum::getLabel).orElse(null);
    }

    /**
     * @param code
     * @return
     */
    public static String getFileName(String code) {
        Optional<YuHongEnum> optional = Arrays.stream(values()).filter(e -> e.getCode().equals(code)).findFirst();
        return optional.map(YuHongEnum::getFileName).orElse(null);
    }

    /**
     * @param type
     * @return
     */
    public static String getCodeByType(String type) {
        Optional<YuHongEnum> optional = Arrays.stream(values()).filter(e -> e.getType().equals(type)).findFirst();
        return optional.map(YuHongEnum::getCode).orElse(null);
    }
}
